#include <iostream>
#include <string>
#include <deque>
#include "Watch.h"
#include "Statistics.h"
#include "Words.h"
#include "UnorderedList.h"

using namespace std;

bool Palindrome( string s );
int RecPalin( string word, int start, int end );

int main3_1( void );
int main3_2( void );
int main3_3( void );
int main4_12( void );

int main( void )
{
	/*main3_1();
	main3_2();
	main3_3();*/

	main4_12();
	cin.get();
	return 0;
}

int RecPalin( string word, int start, int end )
{
	if( start >= end )
		return 1;
	else
	{
		if( word[start] != word[end] )
			return 0;
		else
		{
			return RecPalin( word, start+1, end-1 );
		}
	}
}

bool Palindrome( string s )
{
	deque<char> wordFront;  // Queue behaviour
	deque<char> wordBack;	// Stack behaviour

	char fromQueue = ' ';
	char fromStack = ' ';

	for( auto c : s )
		wordFront.push_back(c);

	for( auto c : s )
		wordBack.push_front(c);

	while( wordFront.size() > 0 )
	{
		fromQueue = wordFront.front();
		wordFront.pop_front();
		fromStack = wordBack.front();
		wordBack.pop_front();
		if( wordFront != wordBack )
		{
			return false;
		}
	}

	return true;

}


int main3_1( void )
{
	cout << "Main3_1();" << endl;

	string str1 = "otto";
	string str2 = "janne";

	cout << "Iterative palindrome with <deque>" << endl;
	cout << str1 << " is palindrome == " << Palindrome( str1 ) << endl;
	cout << str2 << " is palindrome == " << Palindrome( str2 ) << endl;


	cout << "Recursive palindrome" << endl;
	cout << str1 << " is palindrome == " << RecPalin(str1, 0, str1.size() -1 ) << endl;
	cout << str2 << " is palindrome == " << RecPalin(str2, 0, str2.size() -1 ) << endl;

	cin.get();
	return 0;
}

int main3_2( void )
{
	cout << "Main3_2();" << endl;

	U32::Statistics stats;

	stats.ReadFromFile( "salary.txt" );


	cout << "Mean: " << stats.CalculateMean() << endl;
	cout << "Median: " << stats.CalculateMedian() << endl;

	cin.get();
	return 0;
}

int main3_3( void )
{
	cout << "Main3_3();" << endl;

	Course::Watch w1;
	Words words;


	w1.restart();
	words.ReadFromFile( "nils_holgersson.txt" );
	words.MostFrequentWord();

	cout << "Execution time: " << w1.elapsedMs().count() << " ms" << endl;

	cin.get();
	return 0;
}

int main4_12( void )
{
	cout << "Main4_12();" << endl;

	UnorderedList wordList(10000);

	wordList.ReadFromFile( "nils_holgersson.txt" );

	wordList.PrintMaximumFreq();

	cout << "Total number of words: " << wordList.NumberOfWords() << endl;

	cin.get();
	return 0;
}